<?php


namespace App\Listener;

use App\Event\UserCreated;
use App\Service\UserProfilesService;
use Hyperf\Event\Contract\ListenerInterface;

class UserCreatedListener implements ListenerInterface
{
    private UserProfilesService $userProfilesService;

    public function __construct(UserProfilesService $userProfilesService) {
        // 依赖注入容器配置
        $this->userProfilesService = $userProfilesService;
    }

    public function listen(): array
    {
        // 返回一个该监听器要监听的事件数组，可以同时监听多个事件
        return [
            UserCreated::class,
        ];
    }

    public function process(object $event): void {
        // 处理事件
        //此处补全生成 user_profiles 表数据
        $data = [];

        $data['user_id'] = $event->user['id'];
        $this->userProfilesService->initUserProfiles($data);
    }
}